home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE19 / CLINIC / STARTU.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1996-11-04  |  1.6 KB  |  71 lines

  1. unit StartU;
  2.  
  3. interface
  4.  
  5. uses
  6.   WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls,
  7.   Forms, Dialogs;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     procedure FormCreate(Sender: TObject);
  12.   private
  13.     { Private declarations }
  14.   public
  15. {$ifdef Win32}
  16.     procedure DoRestore(Sender: TObject);
  17. {$endif}
  18.   end;
  19.  
  20. var
  21.   Form1: TForm1;
  22.  
  23. implementation
  24.  
  25. {$R *.DFM}
  26.  
  27. {$ifdef Win32}
  28. procedure TForm1.DoRestore(Sender: TObject);
  29. begin
  30.   Application.ShowMainForm := True;
  31.   { Restore application }
  32.   Perform(wm_SysCommand, sc_Restore, 0);
  33.   { This is needed to ensure all components draw properly }
  34.   Show;
  35.   { Disconnect the event handler so this code will not be called again }
  36.   Application.OnRestore := nil;
  37. end;
  38. {$endif}
  39.  
  40. procedure TForm1.FormCreate(Sender: TObject);
  41. begin
  42.   if WindowState = wsNormal then
  43.     case CmdShow of
  44.       sw_ShowNormal, sw_ShowNoActivate, sw_Show,
  45.       sw_ShowNA, sw_Restore: WindowState := wsNormal;
  46.       sw_ShowMinimized, sw_Minimize,
  47.       sw_ShowMinNoActive: WindowState := wsMinimized;
  48.       sw_ShowMaximized: WindowState := wsMaximized;
  49.     end;
  50. {$ifdef Win32}
  51.   if WindowState = wsMinimized then
  52.   begin
  53.     Application.ShowMainForm := False;
  54.     Application.OnRestore := DoRestore;
  55.     Application.Minimize;
  56.   end;
  57. {$endif}
  58. end;
  59.  
  60. {$ifdef Win32}
  61. var
  62.   StartupInfo : TStartupInfo;
  63.  
  64. initialization
  65.   { Set up CmdShow correctly to workaround the fact that }
  66.   { Delphi hardwires it to a value 10 (sw_ShowNormal) }
  67.   GetStartupInfo(StartupInfo);
  68.   CmdShow := StartupInfo.wShowWindow;
  69. {$endif}
  70. end.
  71.